<template>
    <div class="paginationBox">
        <slot >
             <span>共{{total}}条</span>
             <select name="" id="" @change="sizeChange()">
                <option :value="item" v-for="(item,key) in pageSizes" :key="key" >{{item}}条/页</option>
             </select>
             <span class="a">
                <button @click="left"> &lt; </button>
                <button v-for="(item,key) in num" :key="key" @click="currentChange(item)">{{item}}</button>
                 <button @click="right">></button>
             </span>
             <span>
               前往 <input type="text" v-model.number="sum" class="ipt" @blur="changeNum">页
             </span>
        </slot>
       
    </div>
</template>
<script>
export default {
    props:{
        total:{
            type:Number,
            default:40
        },
        pageSize:{
            type:Number,
            default:3
        },
        pageSizes:{
            type:Array
        },
        currentPage:{
            type:Number,
            default:1
        }
    },
    data(){
        return{
            sum:1
        }
    },
    methods:{
        sizeChange(){
            let a = event.target.value
            this.$emit('sizeChange',Number(a))
        },
        currentChange(item){
            this.sum = item
            this.$emit('currentChange',item)
        },
        left(){
            
            this.sum--
            this.$emit('currentChange',this.sum)
        },
        right(){
            this.sum++
            this.$emit('currentChange',this.sum)
        },
        changeNum(){
            this.$emit('currentChange',this.sum)
        }
    },
    computed:{
       num(){
        return Math.ceil(this.total/this.pageSize)
       }
    }
}
</script>

<style lang="scss" scoped>
.paginationBox{
    display: flex;
    justify-content: space-around;
}
.a{
    width: 40%;
    display: flex;
    justify-content: space-around;
    align-items: center;
}
.ipt{
    width: 40px;
    text-align: center;
}
</style>